﻿#define IsTest  //定义一个宏

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace _011_特性
{
    [MyTest("一个简单的特性类", ID = 100)]// 当我们使用的时候，后面的Attribute不需要写
    class Program
    {
        /// <summary>
        /// 旧方法
        /// </summary>
        [Obsolete("这个方法过时了，请使用NewMethod")]
        static void OldMethod()
        {
            Console.WriteLine("OldMethod");
        }

        /// <summary>
        /// 新方法
        /// </summary>
        static void NewMethod()
        {
            Console.WriteLine("NewMethod");
        }
        [Conditional("IsTest")]
        static void Test1()
        {
            Console.WriteLine("test1");
        }

        static void Test2()
        {
            Console.WriteLine("test2");
        }

        [DebuggerStepThrough]
        static void PrintOut(string str,[CallerFilePath]string fileName="",[CallerLineNumber]int lineNumber=0,
            [CallerMemberName]string methodName= "")
        {
            Console.WriteLine(str);
            Console.WriteLine(fileName);
            Console.WriteLine(lineNumber);
            Console.WriteLine(methodName);
        }

        static void Main(string[] args)
        {
            Type type = typeof(Program);
            object[] array = type.GetCustomAttributes(false);
            MyTestAttribute myTest = array[0] as MyTestAttribute;
            Console.WriteLine(myTest.Description);
            Console.ReadKey();
        }
    }
}
